/*
@author: user
@date: 2022/6/16 16:36
@Version: 1.0
@last modifined by : 2022/6/16 16:36
@last Modifined time : 2022/6/16 16:36
*/

import React, { useState, useEffect } from 'react';
import { Button, Result } from 'antd';
import CopyrightStatement from '@C/CopyrightStatement';
import './common.less';

const statusEnum = {
  '403': 'Sorry, you are not authorized to access this page.',
  '404': 'Sorry, the page you visited does not exist.',
  '500': 'Sorry, something went wrong.',
};

const Index = (props = {}) => {
  // eslint-disable-next-line react/prop-types
  const { history = {}, location: { pathname } = {} } = props;
  const [status, setStatus] = useState('404');

  useEffect(() => {
    const errUrl = pathname.split('/');
    setStatus(errUrl.filter((val) => /403|404|500/img.test(val))[0]);
  }, [pathname]);

  return (
    <div className="common-unexpected-resource-style">
      <Result
        status={status}
        title={status}
        subTitle={statusEnum[status]}
        extra={<Button type="primary" onClick={() => history.push('/')}>Back Home</Button>}
      />
      <CopyrightStatement />
    </div>
  );
};

export default Index;
